package cn.tedu.redis.demo.config;

import cn.tedu.redis.demo.pojo.Person;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

@Configuration
public class RedisConfiguration {
    @Bean("redis01")
    public RedisTemplate initRedis01(RedisConnectionFactory factory){
        RedisTemplate redisTemplate = new RedisTemplate();
        redisTemplate.setConnectionFactory(factory);
        // 自定义序列化
        // key值必须在客户端传递String类型的数据，然后通过底层对字符串做序列化
        redisTemplate.setKeySerializer(RedisSerializer.string());
        // value值同上
        redisTemplate.setValueSerializer(RedisSerializer.string());
        return redisTemplate;
    }

    @Bean("redis02")
    public RedisTemplate initRedis02(RedisConnectionFactory factory){
        RedisTemplate redisTemplate = new RedisTemplate();
        redisTemplate.setConnectionFactory(factory);
        // 自定义序列化
        // key值可以是任意Object类型但必须支持Serializable序列化接口
        redisTemplate.setKeySerializer(RedisSerializer.java());
        // value值同上
        redisTemplate.setValueSerializer(RedisSerializer.java());
        return redisTemplate;
    }

    @Bean("redis03")
    public RedisTemplate initRedis03(RedisConnectionFactory factory){
        RedisTemplate redisTemplate = new RedisTemplate();
        redisTemplate.setConnectionFactory(factory);
        // 自定义序列化
        // key值可以是任意Object类型但必须支持Serializable序列化接口
        redisTemplate.setKeySerializer(RedisSerializer.java());
        // value值同上
        redisTemplate.setValueSerializer(RedisSerializer.java());
        return redisTemplate;
    }
}
